package com.agann.util;

import java.util.LinkedList;

import com.agann.model.Memory;
import com.agann.model.Record;

public class StoK extends Memory{
	
	/**
	 * Type Code
	 */
	public static final String TYPE_CODE = "StoK";
	
	private int k,d,sd;
	private LinkedList<Record> kHistory;
	private EMA_Util ema_d, ema_sd;
	private double score, score_k, score_d, score_sd;

	public StoK(String code) {
		super(code);
		//TODO Add Exception Check
		String[] args = code.split("@");
		k = Integer.valueOf(args[1]);
		d = Integer.valueOf(args[1]);
		sd = Integer.valueOf(args[1]);
		ema_d = new EMA_Util(d);
		ema_sd = new EMA_Util(sd);
		score_d = 0;
		score_sd = 0;
	}

	@Override
	public void update(Record record) {
		if (kHistory.size()<k) {
			kHistory.add(record);
		} else {
			score = (record.getClose()-getLa())/(getHa()-getLa());
			//TODO Not Fully Correct
			ema_d.update(score);
			score_d = ema_d.getScore();
			ema_sd.update(score);
			score_sd = ema_sd.getScore();
		}
	}
	
	private static double getLa() {
		return 0;
	}
	
	private static double getHa() {
		return 0;
	}

	@Override
	public void merge(String code) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void change(double rate) {
		// TODO Auto-generated method stub
		
	}

}
